package io.gitee.hechenl.datamultitrans.service.impl;

import cn.hutool.json.JSONUtil;
import io.gitee.hechenl.datamultitrans.http.service.HttpHelper;
import io.gitee.hechenl.datamultitrans.mqtt.MqttClientInitiator;
import io.gitee.hechenl.datamultitrans.mqtt.QosEnum;
import io.gitee.hechenl.datamultitrans.service.IDataTransService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.function.Supplier;

@Service
public class DataTransServiceImpl implements IDataTransService {

    @Autowired
    private HttpHelper httpHelper;
    @Autowired
    private MqttClientInitiator mqttClientInitiator;


    @Override
    public <T> void httpPost(Supplier<T> supplier) {
        httpHelper.post(null, null, 3, 1500, null);
    }

    @Override
    public void mqttPublish(Object content, String pubTopic, QosEnum qos) {
        mqttClientInitiator.publish(qos.getValue(), pubTopic, JSONUtil.toJsonStr(content));
    }
}
